package com.smedi.ismedi.inmail.core.port.adapter.restful;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.inmail.api.dto.request.UserActionLogPageRequest;
import com.smedi.ismedi.inmail.api.dto.request.UserActionLogRequest;
import com.smedi.ismedi.inmail.api.dto.response.UserActionLogResponse;
import com.smedi.ismedi.inmail.api.feign.RemoteUserActionFeignApi;
import com.smedi.ismedi.inmail.core.application.command.UserActionLogPageCommand;
import com.smedi.ismedi.inmail.core.application.query.OverviewQueryService;
import com.smedi.ismedi.inmail.core.application.query.UserActionQueryService;
import com.smedi.ismedi.inmail.core.application.query.vo.UserActionLogVo;
import com.smedi.ismedi.inmail.core.application.service.OverviewApplicationService;
import com.smedi.ismedi.inmail.core.application.service.UserActionApplicationService;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.UserActionLog;
import com.smedi.ismedi.inmail.core.port.adapter.convert.AdapterConverter;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

/**
 * @className: UserActionController
 * @Description: TODO
 * @version: v1.0.0
 * @author: wzx
 * @date: 2022/10/8 11:33
 */

@AllArgsConstructor
@RestController
public class UserActionController implements RemoteUserActionFeignApi {

    private final UserActionQueryService userActionQueryService;

    private final UserActionApplicationService userActionApplicationService;
    private final AdapterConverter adapterConverter;

    @Override
    public ResponseData<PaginationData<UserActionLogResponse>> getUserActionLogPage(UserActionLogPageRequest userActionLogPageRequest) {
        UserActionLogPageCommand command = adapterConverter.userActionLogPageRequestToUserActionLogPageCommand(userActionLogPageRequest);
        Page<UserActionLogVo> page = userActionQueryService.getUserActionLogPage(command);
        PaginationData<UserActionLogResponse> paginationData =adapterConverter.userActionLogPageToUserActionLogResponsePaginationData(page);
        return new ResponseData<>().success(paginationData);
    }

    @Override
    public ResponseData<Boolean> saveUserActionLog(UserActionLogRequest request) {
        UserActionLog actionLog = adapterConverter.userActionRequestToUserActionLog(request);
        if(userActionApplicationService.saveUserActionLog(actionLog)){
            return new ResponseData<>().success(true);
        }
        return new ResponseData<>().success(false);
    }
}